﻿<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
  
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>RogueSharp | RogueSharp </title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="title" content="RogueSharp - RogueSharp ">
    <meta name="generator" content="docfx 2.47.0.0">
    
    <link rel="shortcut icon" href="images/favicon.ico">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/dracula.min.css">
    <link rel="stylesheet" href="styles/site.css">
    <meta property="docfx:navrel" content="toc.html">
    <meta property="docfx:tocrel" content="toc.html">
    
    
    
  </head>
  <body data-spy="scroll" data-target="#affix" data-offset="120">
    <div id="wrapper">
      <header>
        
        <div class="bg-light">
        <nav class="navbar navbar-expand-lg navbar-light bg-light container">
          
          <a class="navbar-brand" href="index.html">
            <img id="logo" class="svg" src="images/logo.svg" alt="RogueSharp" width="36" height="36">
          </a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
        
          <div class="collapse navbar-collapse" id="navbar">
            <!--<form id="search" role="search" class="form-inline my-2 my-lg-0">
              <input id="search-query" class="form-control mr-sm-2" type="search" placeholder="Search" autocomplete="off" aria-label="Search">
            </form>-->
          </div>
        </nav>
        </div>
        
        <div class="bg-dark">
        <nav aria-label="breadcrumb" id="breadcrumb" class="container hide-when-search">
          <!--<ol class="breadcrumb">
            <li class="breadcrumb-item" aria-current="page"></li>
          </ol>-->
        </nav>
        </div>      </header>
      <div role="main" class="container body-content hide-when-search">
      <div class="row">
        <div class="article col">
      <div class="row">
          <div class="col-lg-9">
            <article class="content wrap pt-2 pb-2" id="_content" data-uid="">
<h1 id="roguesharp">RogueSharp</h1>

<p><a href="https://faronbracy.github.io/RogueSharp/articles/01_introduction.html"><img src="https://img.shields.io/badge/tutorials-github.io-blue.svg" alt="Tutorials: Github.io"></a>
<a href="https://faronbracy.github.io/RogueSharp/api/index.html"><img src="https://img.shields.io/badge/docs-github.io-blue.svg" alt="Documentation: Github.io"></a>
<a href="https://roguesharp.wordpress.com/"><img src="https://img.shields.io/badge/blog_posts-wordpress-blue.svg" alt="Posts: Blog"></a>
<a href="https://raw.githubusercontent.com/FaronBracy/RogueSharp/master/LICENSE.txt"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a></p>
<p><a href="https://dreamersdesign.visualstudio.com/RogueSharp/_build/latest?definitionId=1"><img src="https://dreamersdesign.visualstudio.com/RogueSharp/_apis/build/status/RogueSharp%20Continuous" alt="Build status"></a>
<a href="https://ci.appveyor.com/project/FaronBracy/roguesharp-20n28"><img src="https://ci.appveyor.com/api/projects/status/mx09mla59wsgrkkj?svg=true" alt="Build status"></a>
<a href="https://www.nuget.org/packages/RogueSharp"><img src="https://buildstats.info/nuget/roguesharp" alt="Nuget"></a></p>
<p><a href="https://dreamersdesign.visualstudio.com/RogueSharp/_build/latest?definitionId=1"><img src="https://img.shields.io/azure-devops/tests/dreamersdesign/RogueSharp/1.svg" alt="Test status"></a>
<a href="https://dreamersdesign.visualstudio.com/RogueSharp/_build/latest?definitionId=1"><img src="https://img.shields.io/azure-devops/coverage/dreamersdesign/RogueSharp/1.svg" alt="Code coverage"></a></p>
<p><a href="https://ci.appveyor.com/project/FaronBracy/roguesharp-20n28/history"><img src="https://buildstats.info/appveyor/chart/FaronBracy/roguesharp-20n28" alt="Build History"></a></p>
<p><a href="https://github.com/FaronBracy/RogueSharpSadConsoleSamples"><img src="images/Index/sadconsoleport.png" alt="RogueSharp with SadConsole"></a></p>
<ul>
<li><a href="https://github.com/FaronBracy/RogueSharpSadConsoleSamples">Sample Game using RogueSharp with SadConsole</a></li>
<li><a href="https://github.com/FaronBracy/RogueSharpRLNetSamples">Sample Game using RogueSharp with RLNet</a></li>
</ul>
<h2 id="what-is-roguesharp">What is RogueSharp</h2>
<p>RogueSharp is a free library written in C# to help <a href="http://en.wikipedia.org/wiki/Roguelike" title="roguelike">roguelike</a> developers get a head start on their game. RogueSharp provides many utility functions for dealing with map generation, field-of-view calculations, path finding, random number generation and more.</p>
<p>It is loosely based on the popular <a href="https://github.com/libtcod/libtcod" title="libtcod">libtcod</a> or &quot;Doryen Library&quot; though not all features overlap.</p>
<h2 id="getting-started">Getting Started</h2>
<ol>
<li>Visit the <a href="https://roguesharp.wordpress.com/" title="RogueSharp Blog">RogueSharp Blog</a> for tips and tutorials.</li>
<li>The quickest way to add RogueSharp to your project is by using the <a href="https://www.nuget.org/packages/RogueSharp" title="RogueSharp nuget package">RogueSharp nuget package</a>.</li>
<li>If building the assembly yourself, the solution file &quot;RogueSharp.sln&quot; contains the main library and unit tests. This should be all you need.</li>
<li>Class documentation is located on <a href="https://faronbracy.github.io/RogueSharp/api/index.html" title="RogueSharp class documentation">Github Pages</a>.</li>
</ol>
<h2 id="features">Features</h2>
<h3 id="pathfinding">Pathfinding</h3>
<p>With or without diagonals</p>
<p><img src="images/Index/diagonalpathfinder.gif" alt="Pathfinding with Diagonals"></p>
<pre><code class="lang-cs">/// Constructs a new PathFinder instance for the specified Map
/// that will consider diagonal movement by using the specified diagonalCost
public PathFinder( IMap map, double diagonalCost )

/// Returns a shortest Path containing a list of Cells
/// from a specified source Cell to a destination Cell
public Path ShortestPath( ICell source, ICell destination )
</code></pre>
<h3 id="cell-selection">Cell Selection</h3>
<p>Select rows, columns, circles, squares and diamonds with and without borders.</p>
<p><img src="images/Index/selection.gif" alt="Cell Selection"></p>
<pre><code class="lang-cs">/// Get an IEnumerable of Cells in a circle around the center Cell up
/// to the specified radius using Bresenham's midpoint circle algorithm
public IEnumerable&lt;ICell&gt; GetCellsInCircle( int xCenter, int yCenter, int radius )
  
/// Get an IEnumerable of outermost border Cells in a circle around the center
/// Cell up to the specified radius using Bresenham's midpoint circle algorithm
public IEnumerable&lt;ICell&gt; GetBorderCellsInCircle( int xCenter, int yCenter, int radius )
</code></pre>
<h3 id="weighted-goal-maps">Weighted Goal Maps</h3>
<p>Set multiple goals weights for desirability. Add obstacles to avoid.</p>
<p><img src="images/Index/diagonalgoalmap.gif" alt="Weighted Goal Maps"></p>
<pre><code class="lang-cs">/// Constructs a new instance of a GoalMap for the specified Map
/// that will consider diagonal movements to be valid if allowDiagonalMovement is set to true.
public GoalMap( IMap map, bool allowDiagonalMovement )

/// Add a Goal at the specified location with the specified weight
public void AddGoal( int x, int y, int weight )

/// Add an Obstacle at the specified location. Any paths found must not go through Obstacles
public void AddObstacle( int x, int y )
</code></pre>
<h3 id="field-of-view">Field-of-View</h3>
<p>Efficient field-of-view calulation for specified distance. Option to light walls or not.</p>
<p><img src="images/Index/circularfieldofview.gif" alt="Field of View"></p>
<pre><code class="lang-cs">/// Constructs a new FieldOfView objec for the specified Map
public FieldOfView( IMap map )

/// Performs a field-of-view calculation with the specified parameters.
public ReadOnlyCollection&lt;ICell&gt; ComputeFov( int xOrigin, int yOrigin, int radius, bool lightWalls )

/// Performs a field-of-view calculation with the specified parameters
/// and appends it any existing field-of-view calculations.
public ReadOnlyCollection&lt;ICell&gt; AppendFov( int xOrigin, int yOrigin, int radius, bool lightWalls )
</code></pre>
<h2 id="creating-a-map">Creating a Map</h2>
<p>Most interactions with RogueSharp is based around the concept of a <code>Map</code> which is a rectangular grid of <code>Cells</code>.</p>
<p>Each <code>Cell</code> in a <code>Map</code> has the following properties:</p>
<ul>
<li><code>IsTransparent</code>: true if visibility extends through the <code>Cell</code>.</li>
<li><code>IsWalkable</code>: true if a the <code>Cell</code> may be traversed by the player</li>
<li><code>IsExplored</code>: true if the player has ever had line-of-sight to the <code>Cell</code></li>
<li><code>IsInFov</code>: true if the <code>Cell</code> is currently in the player's field-of-view</li>
</ul>
<p>To instantiate a new <code>Map</code> you can use its constructor which takes a width and height and will create a new map of those dimensions with the properties of all <code>Cells</code> set to false.</p>
<h3 id="simple-map-creation---usage">Simple Map Creation - Usage</h3>
<pre><code class="lang-cs">IMap boringMapOfSolidStone = new Map( 5, 3 );
Console.WriteLine( boringMapOfSolidStone.ToString() );
</code></pre>
<h3 id="simple-map-creation---output">Simple Map Creation - Output</h3>
<pre><code class="lang-txt">#####
#####
#####
</code></pre>
<p>Notice that the <code>ToString()</code> operator is overridden on the <code>Map</code> class to provide a simple visual representation of the map. An optional bool parameter can be provided to <code>ToString()</code> to indicate if you want to use the field-of-view or not. If the parameter is not given it defaults to false.</p>
<p>The symbols used are as follows:</p>
<ul>
<li><code>%</code>: <code>Cell</code> is not in field-of-view</li>
<li><code>.</code>: <code>Cell</code> is transparent, walkable, and in field-of-view</li>
<li><code>s</code>: <code>Cell</code> is walkable and in field-of-view (but not transparent)</li>
<li><code>o</code>: <code>Cell</code> is transparent and in field-of-view (but not walkable)</li>
<li><code>#</code>: <code>Cell</code> is in field-of-view (but not transparent or walkable)</li>
</ul>
<p>A more interesting way to create a map is to use the <code>Map</code> class's static method <code>Create</code> which takes an <code>IMapCreationStrategy</code>. Some simple classes implementing <code>IMapCreationStrategy</code> are provided with RogueSharp but this is easily extended by creating your own class that implements the strategy.</p>
<h3 id="random-rooms-map-creation---usage">Random Rooms Map Creation - Usage</h3>
<pre><code class="lang-cs">IMapCreationStrategy&lt;Map&gt; mapCreationStrategy = new RandomRoomsMapCreationStrategy&lt;Map&gt;( 17, 10, 30, 5, 3 )
IMap somewhatInterestingMap = Map.Create( mapCreationStrategy );
Console.WriteLine( somewhatInterestingMap.ToString() );
</code></pre>
<h3 id="random-rooms-map-creation---output">Random Rooms Map Creation - Output</h3>
<pre><code class="lang-txt">#################
#################
##...#######...##
##.............##
###.###....#...##
###...##.#####.##
###...##...###..#
####............#
##############..#
#################
</code></pre>
</article>
            <div id="disqus_thread"></div>
            <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
          </div>
          
          <div class="d-none d-lg-block col-md-3" role="complementary">
            <div class="sideaffix pt-3 pb-3">
              <div class="contribution">
                <ul class="nav">
                  <li>
                    <a href="https://github.com/FaronBracy/RogueSharp.Documentation/blob/master/index.md/#L1" class="contribution-link text-info" title="Improve this Doc">
                    <i class="fal fa-edit fa-fw"></i>
                    <span>Improve this Doc</span>
                    </a>
                  </li>
                </ul>
              </div>
              <!--<div class="github-links">
                  <a class="github-button" href="https://github.com/fszlin/certes" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star fszlin/certes on GitHub">Star</a>
              </div>-->
              <nav class="hidden-print affix mt-2" id="affix">
              <!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
              </nav>
            </div>
          </div>
          </div>
        </div>
      </div>
      </div>
      
      <footer class="bg-secondary">
        <!--<div class="grad-bottom"></div>-->
        <div class="footer bg-secondary">
          <div class="container">
          <div class="d-flex">
            <div class="p-2 flex-grow-1 text-white">
            <a class="text-white" href="https://github.com/FaronBracy/RogueSharp">RogueSharp &copy; 2014-2020 Faron Bracy</a>
            
            </div>
            <div class="p-2">
              <a class="text-white" href="#top">Back to top</a>
            </div>
          </div>
          </div>
        </div>
      </footer>
    </div>
    
    <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.1.0/anchor.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/dos.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/powershell.min.js"></script>
    <script type="text/javascript" src="styles/docfx.js"></script>
  </body>
</html>
